﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace CPPEI.Coolzon.Designer.Views
{
    [ValueConversion(typeof(NodeStatus), typeof(Uri))]
    public class NodeStatusToImage : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Uri ret;
            NodeStatus nodeStatus = (NodeStatus)value;
            switch (nodeStatus)
            {
                case NodeStatus.Add:
                    ret = new Uri("pack://application:,,,/CPPEI.Coolzon.Designer.Views;component/SolutionTreeViewIcon/NodeStatusIcon/Add.png");
                    break;
                case NodeStatus.CheckIn:
                    ret = new Uri("pack://application:,,,/CPPEI.Coolzon.Designer.Views;component/SolutionTreeViewIcon/NodeStatusIcon/CheckIn.png");
                    break;
                case NodeStatus.CheckOut:
                    ret = new Uri("pack://application:,,,/CPPEI.Coolzon.Designer.Views;component/SolutionTreeViewIcon/NodeStatusIcon/CheckOut.png");
                    break;
                case NodeStatus.OthersLocked:
                    ret = new Uri("pack://application:,,,/CPPEI.Coolzon.Designer.Views;component/SolutionTreeViewIcon/NodeStatusIcon/OthersLocked.png");
                    break;
                case NodeStatus.Delete:
                    ret = new Uri("pack://application:,,,/CPPEI.Coolzon.Designer.Views;component/SolutionTreeViewIcon/NodeStatusIcon/Delete.png");
                    break;
                case NodeStatus.NotInSourceControl:
                default:
                    ret = null;
                    break;
            }

            return ret;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            NodeStatus nodeStatus = default(NodeStatus);
            Uri uri = (Uri)value;
            if (uri.AbsoluteUri.IndexOf("Add") >= 0)
            {
                nodeStatus = NodeStatus.Add;
            }
            else if (uri.AbsoluteUri.IndexOf("CheckIn") >= 0)
            {
                nodeStatus = NodeStatus.CheckIn;
            }
            else if (uri.AbsoluteUri.IndexOf("CheckOut") >= 0)
            {
                nodeStatus = NodeStatus.CheckOut;
            }
            else if (uri.AbsoluteUri.IndexOf("OthersLocked") >= 0)
            {
                nodeStatus = NodeStatus.OthersLocked;
            }
            else if (uri.AbsoluteUri.IndexOf("Delete") >= 0)
            {
                nodeStatus = NodeStatus.Delete;
            }
            else
            {
                nodeStatus = NodeStatus.NotInSourceControl;
            }
            return nodeStatus;
        }
    }
}
